package com.sky.module.system.OperLog.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.module.system.OperLog.domain.entity.OperLog;
import com.sky.module.system.OperLog.domain.form.OperLogFormQuery;
import com.sky.module.system.OperLog.mapper.OperLogMapper;
import com.sky.module.system.OperLog.service.OperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @date 2023/3/8 8:36
 **/
@Service
public class OperLogServiceImpl implements OperLogService {

    @Autowired
    private OperLogMapper operLogMapper;

    @Override
    public void save(OperLog operLog) {
//                    operLog.set
        operLogMapper.insert(operLog);
    }

    /***
     * @description 翻页查询操作日志记录
     * @param operLogFormQuery
     * @return java.util.List<com.sky.module.system.OperLog.domain.entity.OperLog>
     * @date 2023/3/8 14:45
     *
     */
    @Override
    public Page<OperLog> queryPage(OperLogFormQuery operLogFormQuery) {
        LambdaQueryWrapper<OperLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(operLogFormQuery.getOperName()), OperLog::getOperName, operLogFormQuery.getOperName());
        // -1 表示查询全部状态的
        // 不等于-1 进行拼装条件
        if (operLogFormQuery.getStatus() != -1) {
            wrapper.eq(StringUtils.isNotBlank(operLogFormQuery.getStatus() + ""), OperLog::getStatus, operLogFormQuery.getStatus());

        }
//         大于等于开始时间
        wrapper.ge(StringUtils.isNotBlank(operLogFormQuery.getBeginTime()), OperLog::getCreateTime, operLogFormQuery.getBeginTime());
        wrapper.le(StringUtils.isNotBlank(operLogFormQuery.getEndTime()), OperLog::getCreateTime, operLogFormQuery.getEndTime());
        Page<OperLog> operLogPage = new Page<>(operLogFormQuery.getPageNum(), operLogFormQuery.getPageSize());
        final Page<OperLog> page = operLogMapper.selectPage(operLogPage, wrapper);
//             TODO 这里应该封装一个工具类，将 只取出我们想要的数据，page里有很多数据是我们不需要的
        return page;
    }

    public static void main(String[] args) {
        OperLogFormQuery operLogFormQuery = new OperLogFormQuery();
        operLogFormQuery.setStatus(-1);
        if (operLogFormQuery.getStatus() != -1) {
            System.out.println("test");
        }
    }
}
